ti.forms={}

ti.forms.dateSelect=function(obj){
	var baseName = new String(obj.name).split('_');
	var fields = ['year','month','day','hour','minute'];
	
	baseName.pop();
	baseName = baseName.join('_');
	if(isNaN(obj.form[baseName].value)){
		//alert('timestamp format');
		var vals = new String(obj.form[baseName].value).replace(/:/g,'-').replace(/\s/g,'-').split('-');
		for (var i = 0; i < fields.length; i++){
			var field = obj.form[baseName+'_'+fields[i]];
			if(typeof(field) == 'object'){
				vals[i] = field.options[field.selectedIndex].value;
			}
		}
	}else{
		var myDate = new Date();
		myDate.setTime(parseInt(obj.form[baseName].value) * 1000);
		var vals = [myDate.getUTCFullYear(),(myDate.getUTCMonth()+1),myDate.getUTCDate(),myDate.getUTCHours(),myDate.getUTCMinutes()];
	}
	for (var i = 0; i < fields.length; i++){
		var field = obj.form[baseName+'_'+fields[i]];
		if(typeof(field) == 'object'){
			vals[i] = field.options[field.selectedIndex].value;
		}
	}
	if(isNaN(obj.form[baseName].value)){
		obj.form[baseName].value = vals[0]+'-'+vals[1]+'-'+vals[2]+' '+vals[3]+':'+vals[4];
	}else{
		obj.form[baseName].value = new Date(vals[0],(vals[1] - 1),vals[2],vals[3],vals[4]).valueOf() / 1000;
	}
}

ti.forms.treeNodeToggle=function(treeName,nodes){
	for (var i = 0; i < nodes.length; i++){
		var obj = ti(treeName+'_'+nodes[i]).style;
		obj.display = (obj.display=='none')?'':'none';
	}	
	//alert('ttogling: '+arguments[0].join('/'));
}

ti.forms.setOptList=function(id,newOpts){
	var obj = ti(id);
	while(obj.options.length > 0){
		obj.options[obj.options.length-1] = null;
	}
	for (var i = 0; i < newOpts.length; i++){
		obj.options[i] = new Option(newOpts[i][1],newOpts[i][0]);
	}
	
}